<?php 
// this script is usually not supposed to work
die();

require_once("./../models/config.php");
require_once("./../ui.php");

// lines of name:password:mail
$importString = "";

$success = true;

$lines = explode("\n", $importString);
foreach ($lines as $i => $line) {
	
	$items = explode(":", $line);
	
	//Construct a user object
	$user = new User($items[0], $items[0], $items[1], $items[2]);
	
	//Checking this flag tells us whether there were any errors such as possible data duplication occured
	if(!$user->status)
	{
		if($user->username_taken) $errors[] = lang("ACCOUNT_USERNAME_IN_USE",array($login));
		if($user->email_taken) 	  $errors[] = lang("ACCOUNT_EMAIL_IN_USE",array($email));

		$success = false;
	}
	else
	{
		//Attempt to add the user to the database, carry out finishing  tasks like emailing the user (if required)
		if(!$user->userCakeAddUser())
		{
			if($user->mail_failure) $errors[] = lang("MAIL_ERROR");
			if($user->sql_failure)  $errors[] = lang("SQL_ERROR");
			
			$success = false;
		}
	}
	
	if (!$success) {
		break;
	}
}
?>

<?php printPageHead(null, null); ?>

	<div id="content" class="container_16 clearfix">
	<?php
		global $success;
		if(!$success) {
	?>
            <div id="errors">
            	<h2><?php echo lang("IMPORT_USERS_NOT_ADDED"); ?></h2>
	        	    <?php errorBlock($errors); ?>
            </div>     
	<?php
    	} else {
          
			$message = lang("IMPORT_USERS_ADDED");
	?> 
	        <div id="success">
	           <h2><?php echo $message ?></h2>           
	        </div>
        
   	<?php
		}
	?>
	</div>	
<?php printPageFoot(); ?>
